<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Route_links
{
    private $_CI;
    var $route_details;

    public function __construct()
    {
        $this->_CI = & get_instance();
        include(APPPATH . 'config/routesDB.php');
        if (isset($route))
            $this->route_details = $route;
    }

    public function build_link($route_name, $search_replace = array())
    {
        $url = $this->get($route_name, $search_replace);

        return $this->_CI->config->site_url($url);
    }

    public function get($route_name, $search_replace = array())
    {
        if (!isset($this->route_details[$route_name]))
            return false;
        $route = $this->route_details[$route_name];
        $url = $route['url'];
        if (!empty($search_replace)) {
            foreach ($search_replace as $f => $r) {
                $find[] = $f;
                $replace[] = $r;
            }
            $url = str_replace($find, $replace, $url);
        }
        return $url;
    }
}